package
{
	import flash.geom.Matrix;
	import flash.display.BitmapData;
	import flash.display.Shader;
	import flash.display.Graphics;
	import flash.display.IGraphicsPath;
	import flash.display.IGraphicsFill;
	import flash.display.IGraphicsStroke;
	import flash.display.IGraphicsData;
	import flash.display.Sprite;
	import flash.display.DisplayObject;
	
	/*
	 *地图块绘制类
	 *不可构造
	 * 绘制类型
	 * t1:平行四边形
	 * t2:正方形
	 * t3:\型四边形
	 * t4:/型四边形
	 * t5:长方形
	 */
	//Game_graphing 类
	public class Game_graphing
	{
		//实际坐标
		static private var rx:Number;
		static private var ry:Number;
		
		//主程序
		public static function main(mx:int, my:int, mz:int, type:String):Sprite
		{
			switch (type)
			{
				case "t1": 
					return Game_graphing.drew_new_t1(mx, my, mz);
					break;
				case "t3": 
					return Game_graphing.drew_new_t3(mx, my, mz);
					break;
				case "t4": 
					return Game_graphing.drew_new_t4(mx, my, mz);
					break;
				case "t2": 
					return Game_graphing.drew_new_t2(mx, my, mz);
					break;
				case "t5": 
					return Game_graphing.drew_new_t5(mx, my, mz);
					break;
				default: 
					trace("绘制类型非法!")
					return null
					break
			}
		
		}
		
		//平行四边形
		public static function drew_new_t1(mx:int, my:int, mz:int):Sprite
		{
			Game_graphing.convert_m2r(mx, my, mz)
			var sprite_tile:Sprite = new Sprite();
			sprite_tile.graphics.clear();
			sprite_tile.graphics.lineStyle(1, 0x00000, 0);
			sprite_tile.graphics.beginFill(0x000000);
			sprite_tile.graphics.moveTo(-17.3 + rx, 0 + ry);
			sprite_tile.graphics.lineTo(0 + rx, 10 + ry);
			sprite_tile.graphics.lineTo(17.3 + rx, 0 + ry);
			sprite_tile.graphics.lineTo(0 + rx, -10 + ry);
			sprite_tile.graphics.lineTo(-17.3 + rx, 0 + ry);
			sprite_tile.graphics.endFill();
			return sprite_tile;
		}
		
		//\型四边形
		public static function drew_new_t3(mx:int, my:int, mz:int):Sprite
		{
			Game_graphing.convert_m2r(mx, my, mz)
			var sprite_tile:Sprite = new Sprite();
			sprite_tile.graphics.clear();
			sprite_tile.graphics.lineStyle(1, 0x00000, 0);
			sprite_tile.graphics.beginFill(0xCCCCCC);
			sprite_tile.graphics.moveTo(-17.3 + rx, 0 + ry);
			sprite_tile.graphics.lineTo(-17.3 + rx, 10 + ry);
			sprite_tile.graphics.lineTo(0 + rx, 20 + ry);
			sprite_tile.graphics.lineTo(0 + rx, 10 + ry);
			sprite_tile.graphics.lineTo(-17.3 + rx, 0 + ry);
			sprite_tile.graphics.endFill();
			return sprite_tile;
		}
		
		//正方形
		public static function drew_new_t2(mx:int, my:int, mz:int):Sprite
		{
			Game_graphing.convert_m2r2(mx, my, mz)
			var sprite_tile:Sprite = new Sprite();
			sprite_tile.graphics.clear();
			sprite_tile.graphics.lineStyle(1, 0x00000, 0);
			sprite_tile.graphics.beginFill(0x000000);
			sprite_tile.graphics.moveTo(-10 + rx, -10 + ry);
			sprite_tile.graphics.lineTo(-10 + rx, 10 + ry);
			sprite_tile.graphics.lineTo(10 + rx, 10 + ry);
			sprite_tile.graphics.lineTo(10 + rx, -10 + ry);
			sprite_tile.graphics.lineTo(10 + rx, -10 + ry);
			sprite_tile.graphics.endFill();
			return sprite_tile;
		}
		
		//长方形
		public static function drew_new_t5(mx:int, my:int, mz:int):Sprite
		{
			Game_graphing.convert_m2r2(mx, my, mz)
			var sprite_tile:Sprite = new Sprite();
			sprite_tile.graphics.clear();
			sprite_tile.graphics.lineStyle(1, 0x00000, 0);
			sprite_tile.graphics.beginFill(0x666666);
			sprite_tile.graphics.moveTo(-10 + rx, 10 + ry);
			sprite_tile.graphics.lineTo(-10 + rx, 20 + ry);
			sprite_tile.graphics.lineTo(10 + rx, 20 + ry);
			sprite_tile.graphics.lineTo(10 + rx, 10 + ry);
			sprite_tile.graphics.lineTo(-10 + rx, 10 + ry);
			sprite_tile.graphics.endFill();
			return sprite_tile;
		}
		
		///型四边形
		public static function drew_new_t4(mx:int, my:int, mz:int):Sprite
		{
			Game_graphing.convert_m2r(mx, my, mz)
			var sprite_tile:Sprite = new Sprite();
			sprite_tile.graphics.clear();
			sprite_tile.graphics.lineStyle(1, 0x00000, 0);
			sprite_tile.graphics.beginFill(0x666666);
			sprite_tile.graphics.moveTo(17.3 + rx, 0 + ry);
			sprite_tile.graphics.lineTo(17.3 + rx, 10 + ry);
			sprite_tile.graphics.lineTo(0 + rx, 20 + ry);
			sprite_tile.graphics.lineTo(0 + rx, 10 + ry);
			sprite_tile.graphics.lineTo(17.3 + rx, 0 + ry);
			sprite_tile.graphics.endFill();
			return sprite_tile;
		}
		
		//坐标转换(坐标序号 >> 舞台坐标)(45度)
		static function convert_m2r(ix:int, iy:int, iz:int):void
		{
			rx = 10.5 * Math.sqrt(3) * (ix - iy) 
			ry = 10.5 * (ix + iy - iz) 
		}
		
		//坐标转换(坐标序号 >> 舞台坐标)(横版)
		static function convert_m2r2(ix:int, iy:int, iz:int):void
		{
			rx = 10.5 * ix
			ry = 10.5 * iy + 5 * iz
		}
	}
}